package org.yenn.pattern.cor;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.yenn.pattern.cor.handler.PriceHandler;
import org.yenn.pattern.cor.handler.PriceHandlerFactory;

import java.util.Random;

/*
 * 客户，请求折扣
 */
@Slf4j
public class Customer {

	@Setter
	private PriceHandler priceHandler;

	public void requestDiscount(float discount){
		priceHandler.processDiscount(discount);
	}


	public static void main(String[] args){
		Customer customer = new Customer();
		PriceHandler priceHandler = PriceHandlerFactory.createPriceHandler();
		log.info("priceHandler={}",priceHandler);
		customer.setPriceHandler(priceHandler);

		Random rand = new Random();


		for(int i=1;i<=100;i++){
			float cutoff = rand.nextFloat(); // 折扣
			System.out.print(i+":"+cutoff+"---------------");
			customer.requestDiscount(cutoff);

		}
	}
}
